﻿using RecruitStudents.Utility.Config;
using RecruitStudents.Utility.Const;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RecruitStudents.Utility.Model;
using System.Data;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Json;

namespace RecruitStudents.Client.BLL
{
    public class ServiceComm
    {
        WS_Comm.CommService commService = new WS_Comm.CommService();
        WS_Comm.MySoapHeader objHeader = new WS_Comm.MySoapHeader();
        internal ServiceComm()
        {
            objHeader.Username = "admin";
            objHeader.Password = "xy";
            commService.MySoapHeaderValue = objHeader;
        }

        public DataTable GetExamLevelTable()
        {
            return commService.GetExamLevelTable().ToDataTable();
        }
        internal bool SaveSystemInfo(List<TB_Sys_SystemInfo> list)
        {
            try
            {
                string strJson = list.ToJson();
                DevHelper.ShowWaiting();
                var obj = commService.SaveSystemInfo(strJson);
                var result = obj.ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        internal DataTable GetDicDataTableByDicTableName(string dicTableName)
        {
            return commService.GetDicDataTableByDicTableName(dicTableName).ToDataTable();
        }
        internal DateTime GetSystemDateTime()
        {
            return commService.GetSystemDateTime().ToSafeDateTime();
        }
        internal DataTable GetSystemInfoDataTable(string strSystemInfoID)
        {
            return commService.GetSystemInfoDataTable(strSystemInfoID).ToDataTable();
        }

        internal TB_Sys_SystemInfo GetSystemInfoModel(string strSystemInfoID)
        {
            return commService.GetSystemInfoModel(strSystemInfoID).ToList<TB_Sys_SystemInfo>();
        }

        #region CS端登陆
        internal DataTable GetRoleAuth(string roleID)
        {
            return commService.GetRoleAuthModuleTable(roleID).ToDataTable();
        }
        internal TB_Sys_User LoginUser(string strLoginName, string strPassWord)
        {
            try
            {
                return commService.GetUserLogin(strLoginName, strPassWord).ToList<TB_Sys_User>();
            }
            catch(Exception ex)
            {
                return null;
            }
        }
        internal DataTable GetExamPlaceTableALL_CS()
        {
            return commService.GetExamPlaceTableALL_CS().ToDataTable();
        }
        internal DataTable GetExamLevelByPlaceID_Speciality_CS(string examPlaceID, string specialityKindsNO)
        {
            return commService.GetExamLevelByPlaceID_Speciality_CS(examPlaceID, specialityKindsNO).ToDataTable();
        }
        internal DataTable GetSpecialityKindsTableByExamPlaceID_CS(string examPlaceID)
        {
            return commService.GetSpecialityKindsTableByExamPlaceID_CS(examPlaceID).ToDataTable();
        }
        internal TB_Exam_Entretenimientoh GetEntretenimientohModel(string examLevel, string examPlaceID, string specialityKindsNO)
        {
            return commService.GetEntretenimientohModel(examLevel, examPlaceID, specialityKindsNO).ToList<TB_Exam_Entretenimientoh>();
        }
        internal DataTable GetExamRoomByPlaceID_Speciality_Level_CS(string examPlaceID, string specialityKindsNO, string examLevel)
        {
            return commService.GetExamRoomByPlaceID_Speciality_Level_CS(examPlaceID, specialityKindsNO, examLevel).ToDataTable();
        }
        #endregion

        #region 报名专用
        /// <summary>
        /// 根据身份证号码解析出出生日期，性别 
        /// </summary>
        /// <param name="strIdentityCard"></param>
        /// <returns></returns>
        public List<string> GetBirthSexByIdCard(string strIdentityCard)
        {
            return commService.GetBirthSexByIdCard(strIdentityCard).ToList<List<string>>();
        }

        /// <summary>
        /// 根据高考号获取生源地,如果解析出一个生源地只读，大于一个可以让用户来进行选择报考
        /// </summary>
        /// <param name="strNMT_SignUpID"></param>
        /// <returns></returns>
        public DataTable GetProviceTable(string strNMT_SignUpID)
        {
            return commService.GetProviceTable(strNMT_SignUpID).ToDataTable();
        }

        /// <summary>
        /// 获取所有考点
        /// </summary>
        /// <returns></returns>
        public DataTable GetExamPlaceTable()
        {
            return commService.GetExamPlaceTable().ToDataTable();
        }

        /// <summary>
        /// 获取考点列表（报名专用，需要用生源地过滤）
        /// </summary>
        /// <returns></returns>
        public DataTable GetExamPlaceTable_ExamProvince_Limt(string strExamProvince)
        {
            return commService.GetExamPlaceTable_ExamProvince_Limt(strExamProvince).ToDataTable();
        }

        /// <summary>
        /// 根据考点获取专业（报名专用，需要用性别过滤）
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <returns></returns>
        public DataTable GetSpecialityKindsTableByExamPlaceID(string strExamPlaceID, string strSex)
        {
            return commService.GetSpecialityKindsTableByExamPlaceID(strExamPlaceID, strSex).ToDataTable();
        }

        /// <summary>
        /// 根据考点,专业,级别获取分组  兼容报名获取初试考试时间   
        /// </summary>
        /// <param name="examPlaceNo"></param>
        /// <param name="specialityKindsNo"></param>
        /// <param name="examLevel"></param>
        /// <returns></returns>
        public DataTable GetAppointmentGroupDataTable(string strExamPlaceNO, string strSpecialityKindsNO, string strExamLevel)
        {
            return commService.GetAppointmentGroupDataTable(strExamPlaceNO, strSpecialityKindsNO, strExamLevel).ToDataTable();
        }

        /// <summary>
        /// 验证身份证号或高考报名号是否存在
        /// </summary>
        /// <param name="strIdCard">身份证号</param>
        /// <param name="strNMT_SignUpID">高考报名号</param>
        /// <param name="strFlag">0验证身份证号，1验证高考报名号</param>
        /// <returns></returns>
        public JsonMessage StudentInfoModify_CheckIsRegist(string strIdCard, string strNMT_SignUpID, string strFlag)
        {
            return commService.StudentInfoModify_CheckIsRegist(strIdCard, strNMT_SignUpID, strFlag).ToList<JsonMessage>();
        }
        #endregion


        /// <summary>
        /// 根据考场获取考官列表
        /// </summary>
        /// <param name="strRoomID"></param>
        /// <returns></returns>
        internal DataTable GetTeacherList(string strRoomID)
        {
            return commService.GetTeacherList(strRoomID).ToDataTable();
        }
        /// <summary>
        /// 通过考务ID获取考场列表
        /// </summary>
        /// <param name="EntretenimientohID"></param>
        /// <returns></returns>
        internal DataTable GetExamRoomTableByEntretenimientohID(string EntretenimientohID)
        {
            return commService.GetExamRoomTableByEntretenimientohID(EntretenimientohID).ToDataTable();
        }

        internal DataTable GetSpecialityKindsTable(string strExamYear)
        {
            return commService.GetSpecialityKindsTable(strExamYear).ToDataTable();
        }
        /// <summary>
        /// 生成订单编号
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <param name="strSpecialityKindsNO"></param>
        /// <returns></returns>
        internal string CreateOrderNo()
        {
            return commService.CreateOrderNo();
        }

        /// <summary>
        /// 根据考点和专业生成准考证号
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <param name="strSpecialityKindsNO"></param>
        /// <returns></returns>
        internal string CreateExamAllowExamID(string strExamPlaceID, string strSpecialityKindsNO, string strExamYear)
        {
            return commService.CreateExamAllowExamID(strExamPlaceID, strSpecialityKindsNO, strExamYear);
        }

        /// <summary>
        /// 生成抽签号
        /// </summary>
        /// <param name="strExamPlaceID"></param>
        /// <param name="strSpecialityKindsNO"></param>
        /// <returns></returns>
        internal string CreateExamLotNO(string strExamPlaceID, string strExamLevel, string strSpecialityKindsNO, string strExamYear)
        {
            return commService.CreateExamLotNO(strExamPlaceID,strExamLevel,strSpecialityKindsNO,strExamYear);
        }

        /// <summary>
        /// 生成抽签号,开始号和最大号
        /// </summary>
        /// <param name="appointmentgroupid"></param>
        /// <returns></returns>
        internal string CreateLotteryNO(string appointmentgroupid)
        {
            return commService.CreateLotteryNO(appointmentgroupid);
        }

        public DataTable GetExamProvinceDataTable()
        {
            return commService.GetExamProvinceDataTable().ToDataTable();
        }

        public DataTable GetEaxmLogTable(string strSigUpID, string strSignUpStudentsSpecialityID, string strSpecialityKindsNO, string strExamPlaceNo)
        {
            return commService.GetEaxmLogTable(strSigUpID, strSignUpStudentsSpecialityID, strSpecialityKindsNO, strExamPlaceNo).ToDataTable();
        }

        public bool SaveExamLog(TB_Exam_Log model)
        {
            try
            {
                string strJson = model.ToJson();
                var obj = commService.SaveExamLog(strJson);
                var result = obj.ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
    }
}
